from django.shortcuts import render
from models_goods.oo import AllAssetName
from models_goods.models import *
from ribbon.views import permission
from .oo import Inquire, get_random_text
from django.http import HttpResponse


@permission
def inquire(request):
    page, asset = request.GET.get('page'), request.GET.get('asset')  # 获取参数
    asset_name = AllAssetName().get_info()             # 获取选项列表
    if request.method == 'GET' and not asset:          # 刚进入情况下
        duanzi = get_random_text()
    elif request.method == 'GET' and asset:            # 查询情况下
        show_lines = Inquire(StockControl, asset)      # 实例化对象
        show_lines = show_lines.get_page(page if page else 1, show_lines.get_inquire())  # 获取页数对象
        sum_number = (list(range(1, int(show_lines[1])+1)), show_lines[1])  # 页数列表 and 总页数
        show_lines = show_lines[0]                         # 获取数据迭代对象
        asset = int(asset)
    else:
        return HttpResponse('数据非法')                 # 数据非法情况下
    return render(request, 'inquire/inquire.html', locals())


# show_lines.has_next(),  # 是否有下一页
# show_lines.has_previous(),  # 是否有前一页
# show_lines.has_other_pages(),  # 是否有其他页
# show_lines.number,  # 当前页
# sum_number,  # 总页数
# show_lines.next_page_number()  # 下一页地址，需要判断，没有会报错
